package com.mhxy.service.impl;

import com.mhxy.constant.PicConstants;
import com.mhxy.service.AbstractTask;
import com.mhxy.util.DateUtil;
import com.mhxy.util.FuzzyPicUtil;
import com.mhxy.util.ThreadUtil;
import com.mhxy.util.TimeUtil;
import com.sun.jna.platform.win32.WinDef;
import lombok.extern.slf4j.Slf4j;

/**
 * 勇闯迷魂塔
 */
@Slf4j
public class ClimbTowerTaskImpl extends AbstractTask {
    public ClimbTowerTaskImpl(WinDef.HWND hwnd_0) {
        super(hwnd_0);
    }

    @Override
    public Boolean before() throws Exception {
        if (DateUtil.getNowDay() != 5) {
            log.error("【{}】今天不是周五，任务结束！", getTaskName());
            return false;
        }
        if (TimeUtil.isAfter(22, 0)) {
            log.error("【{}】活动时间已过！", getTaskName());
            return false;
        }
        return true;
    }

    @Override
    public Boolean execute() throws Exception {
        int times = 30;
        while (findAndClickTaskList(PicConstants.公共_任务列表_勇闯迷魂塔) && times > 0) {
            times--;
            ThreadUtil.sleep3();
            for (int i = 0; i < 10; i++) {
                if (FuzzyPicUtil.findAndClickRandom(hwnd_0, PicConstants.普通副本_进入战斗)) {
                    break;
                }
                ThreadUtil.sleep1();
            }

            findBattle(3000);
            ThreadUtil.sleep1();
        }
        return true;
    }

    @Override
    public Boolean after() throws Exception {
        return true;
    }

    @Override
    public String getTaskName() throws Exception {
        return "勇闯迷魂塔";
    }
}
